﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.WindowsAzure.StorageClient;

namespace Bowlus.Common
{
    // This is used to represent a Tenant >> Application >> Instance Mapping
    public class TenantDeployment : TableServiceEntity, IComparable
    {
        // partition key = '_bowlus'
        public TenantDeployment() : base("_bowlus", null) { }

        // The tenant identifier. RowKey and TenantId.
        // ie. 'test1'. 
        public string TenantId
        {
            get
            {
                return this.RowKey;
            }
            set
            {
                this.RowKey = value;
            }
        }

        // Tenant Host Name HOST_HEADER for provisioning and routing. 
        // ie. 'test1.bowlus.net'
        public string HostName { get; set; }

        // app code zip file. 
        // ie. 'site1.2.zip'
        public string Application { get; set; }

        // app code customization zip file. 
        // ie. 'custome1.zip'
        public string AppCustom { get; set; }

        // The CURRENT AppHost Instance the tenant is deployed and routed.
        // ie. '127.255.0.0'
        public string Instance { get; set; }

        // The CURRENT AppHost Instance Name.
        // ie. 'deployment(16).Bowlus.Bowlus.AppHost_IN_0'
        public string InstanceId { get; set; }

        // The CURRENT AppHost Instance Status
        // ie. 'active', ''
        public string Status { get; set; }

        // The Staging Instance: Deployment Target Instance, or To-be-undeployed Instance.
        public string Staging { get; set; }

        // The Staging Instance Id: Deployment Target Instance, or To-be-undeployed Instance.
        public string StagingId { get; set; }

        // The Staging Instance Status.
        // ie. 'provisioning', 'provisioned', 'deprovisioning'
        public string SStatus { get; set; }

        public static readonly string S_ACTIVE = "active";
        public static readonly string S_MOVE = "move";
        public static readonly string S_REMOVE = "remove";
        public static readonly string S_PROVISIONING = "provisioning";
        public static readonly string S_PROVISIONED = "provisioned";
        public static readonly string S_DEPROVISIONING = "deprovisioning";

        public int CompareTo(object obj)
        {
            if (obj != null && obj is TenantDeployment)
            {
                TenantDeployment td = obj as TenantDeployment;
                return TenantId.CompareTo(td.TenantId);
            }
            return -1;
        }
    }
}
